home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / raytrace / rayshade / graphtal.lzh / Graphtal.Amiga / main.C < prev    next >
C/C++ Source or Header  |  1993-03-09  |  4KB  |  149 lines

  1. /*
  2.  * main.C
  3.  *
  4.  * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
  5.  *                     University of Berne, Switzerland
  6.  * All rights reserved.
  7.  *
  8.  * This software may be freely copied, modified, and redistributed
  9.  * provided that this copyright notice is preserved on all copies.
  10.  *
  11.  * You may not distribute this software, in whole or in part, as part of
  12.  * any commercial product without the express consent of the authors.
  13.  *
  14.  * There is no warranty or other guarantee of fitness of this software
  15.  * for any purpose.  It is provided solely "as is".
  16.  *
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include <stream.h>
  21. #include <stdlib.h>
  22. #include <new.h>
  23.  
  24. #include "globals.h"
  25. #include "Options.h"
  26. #include "LSystem.h"
  27. #include "Interpreter.h"
  28. #include "Color.h"
  29. #include "BBoxDevice.h"
  30. #include "ExampleDevice.h"
  31. #include "RayshadeDevice.h"
  32. #include "FlatDevice.h"
  33.  
  34. #ifdef SUPPORT_X11
  35. # include "LineDevice.h"
  36. # include "WireDevice.h"
  37. # include "X11_Window.h"
  38. #endif
  39.  
  40. #ifdef SUPPORT_AMIGA
  41. # include "LineDevice.h"
  42. # include "WireDevice.h"
  43. # include "AMIGA_Window.h"
  44. #endif
  45.  
  46. extern int yyparse(void);
  47. extern LSystem* lsystem;
  48. extern FILE* yyin;      
  49.  
  50. void memory_error_handler();
  51.  
  52. int main(int argc, char** argv)
  53. {
  54. #if !defined(__GNUC__) && !defined (_AIX) && !defined(__DECCXX)
  55.   mallopt(M_MXFAST, 32);
  56. #endif
  57.  
  58.   set_new_handler(memory_error_handler);
  59.  
  60.   /*
  61.    * Parse the command line options to get name of input file.
  62.    */
  63.   parseOptions(argc, argv);
  64.   Color::setupColors();
  65.  
  66.   rcString cmd(CPP_NAME);
  67.  
  68.   if (theOptions.iname != "cin") 
  69.     cmd = cmd + " " + theOptions.iname + theOptions.optionsForCPP;
  70.   else
  71.     cmd = cmd + " " + theOptions.optionsForCPP;
  72.  
  73.   if ((yyin = popen(cmd.chars(), "r")) == NULL)
  74.     Error(ERR_PANIC, theOptions.iname +  ": no such file");
  75.  
  76.   if (!yyparse()) {
  77.     /*
  78.      * Parse a second time, because command line options overrides
  79.      * the settings in lsys-file.
  80.      */
  81.     parseOptions(argc, argv);
  82.  
  83.     if (theOptions.printlsys)
  84.       cerr << *lsystem << "\n";
  85.  
  86.     ModuleList* result = lsystem->execute();
  87.     if (theOptions.printModules) {
  88.       cerr << '\n';
  89.       for (register long i=0; i<result->count(); i++) 
  90.     cerr << *result->item(i) << "\n"; 
  91.     }
  92.  
  93.     /*
  94.      * Select output driver and start turtle interpretation.
  95.      */
  96.     DeviceDriver* d;
  97.     if (theOptions.drivername == "no")
  98.       return 1;
  99.     else if (theOptions.drivername == "example")
  100.       d = new ExampleDevice;
  101.     else if (theOptions.drivername == "bbox")
  102.       d = new BBoxDevice(&theOptions);
  103.     else if (theOptions.drivername == "rayshade")
  104.       d = new RayshadeDevice(&theOptions);
  105.     else if (theOptions.drivername == "flat")
  106.       d = new FlatDevice(&theOptions);
  107. #ifdef SUPPORT_X11
  108.     else if (theOptions.drivername == "x11simple")
  109.       d = new LineDevice(new X11_Window, &theOptions);
  110.     else if (theOptions.drivername == "x11wire")
  111.       d = new WireDevice(new X11_Window, &theOptions);
  112. #endif
  113. #ifdef SUPPORT_AMIGA
  114.     else if (theOptions.drivername == "amigasimple")
  115.       d = new LineDevice(new AMIGA_Window, &theOptions);
  116.     else if (theOptions.drivername == "amigawire")
  117.       d = new WireDevice(new AMIGA_Window, &theOptions);
  118. #endif
  119.     else {
  120.       if (!theOptions.quiet)
  121. #ifdef SUPPORT_X11
  122.     cerr << "\nUnknown driver specified, using simple X11.\n\n";
  123.       d = new LineDevice(new X11_Window, &theOptions);
  124. #else
  125. #ifdef SUPPORT_AMIGA
  126.     cerr << "\nUnknown driver specified, using simple AMIGA.\n\n";
  127.       d = new LineDevice(new AMIGA_Window, &theOptions);
  128. #else
  129.     cerr << "\nUnknown driver specified, using ExampleDevice.\n\n";
  130.       d = new ExampleDevice;
  131. #endif
  132. #endif
  133.     }
  134.  
  135.     d->setName(lsystem->getName());
  136.     Interpreter interp(d, &theOptions);
  137.     interp.interpret(result);
  138.     // delete d;  let the system do the clean up.
  139.   }
  140.  
  141.   return 1;
  142. }
  143.  
  144. void memory_error_handler()
  145. {
  146.   cerr << "Fatal error: out of memory\n";
  147.   exit(1);
  148. }
  149.